import javax.swing.*;
import java.awt.event.ActionListener;

/**
 * ****************************************************************************
 * $Author: Yegor Chemisov $
 * $Revision: 1.4 $
 * ****************************************************************************
 */

public class MemoryButton
{
    private JButton             button;
    private boolean             status;
    private ImageIcon           faceImage;
    private static ImageIcon    backImage;

    public MemoryButton(String actionCommand, ActionListener obj)
    {
        status      = false;
        button      = new JButton(backImage);
        button.setActionCommand(actionCommand);
        button.addActionListener(obj);
    }


    public MemoryButton(ImageIcon image, String actionCommand, ActionListener obj)
    {
        status      = true;
        faceImage   = image;
        button      = new JButton(faceImage);
        button.setActionCommand(actionCommand);
        button.addActionListener(obj);
    }

    public static void setBackImage(ImageIcon image)
    {
        backImage = image;
    }

    public void setFaceImage(ImageIcon image)
    {
        faceImage = image;
    }

    public void turnOn()
    {
        button.setIcon(faceImage);
        status = true;
    }

    public void turnOff()
    {
        button.setIcon(backImage);
        status = false;
    }

    public void hide()
    {
        button.setVisible(false);
    }

    public void show()
    {
        button.setVisible(true);
    }

    public boolean isOn()
    {
        return status;
    }

    public boolean isOff()
    {
        return !status;
    }

    public JButton getButton()
    {
        return button;
    }

    public boolean equals(MemoryButton value)
    {
        return value.faceImage == this.faceImage;
    }
}
